package com.office.supplies.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.office.supplies.pojo.Stock;
import com.office.supplies.pojo.dto.SelectStockDTO;
import com.office.supplies.pojo.vo.SelectStockVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author admin
 * @Description TODO
 * @Date 2023/12/11/0:52
 */
@Mapper
public interface StockMapper extends BaseMapper<Stock> {

    /**
     * 新增库存
     *
     * @param stock Stock
     */
    @Insert("insert into stock (goods_id, goods_count, create_date)" +
            " value (#{goodsId},#{goodsCount},#{createDate})")
    void insertStock(Stock stock);

    /**
     * 根据goods_id查询商品在库存中的个数
     *
     * @param goodsId Long
     * @return int
     */
    @Select("select * from stock where goods_id = #{goodsId}")
    Stock getGoodsCountByGoodsId(Long goodsId);

    /**
     * 根据goodsId更新库存数量
     *
     * @param stock Stock
     */
    @Update("update stock set goods_count = #{goodsCount}, create_date = #{createDate} where goods_id = #{goodsId}")
    void setGoodsCount(Stock stock);

    /**
     * 根据goodsId删除库存
     *
     * @param goodsId Long
     */
    @Delete("delete from stock where goods_id = #{goodsId}")
    void deleteStockByGoodsId(Long goodsId);

    /**
     * 条件查询库存
     *
     * @param selectStockDTO SelectStockDTO
     * @return List<SelectStockVO>
     */
    List<SelectStockVO> getStockListByCondition(SelectStockDTO selectStockDTO);

    /**
     * 库存余量
     *
     * @return int
     */
    @Select("select sum(stock.goods_count) from stock")
    int getStockCount();

    @Select("select count(goods_id) from stock where goods_id = #{goodsId}")
    int selectStockByGoodsId(Long goodsId);

}
